import { getClassifyApi, addClassifyApi, deleteClassifyApi, updateClassifyApi } from '../../api/audit/index'
export const state = () => ({
    tableData: []
})

export const mutations = {
    SET_LIST(state, data) {
        state.tableData = data
    },
}

export const actions = {
    // 获取列表
    async getClassify({ commit }) {
        const r = await getClassifyApi()
        commit('SET_LIST', r.data)
    },

    // 新增列表
    async addClassify({ dispatch, commit }, data) {
        const r = await addClassifyApi(data)
        dispatch('getClassify')
    },

    // 修改列表
    async updateClassify({ dispatch, commit }, data) {
        // console.log(data);
        const r = await updateClassifyApi(data)
        dispatch('getClassify')
    },

    // 删除列表
    async deleteClassify({ dispatch, commit }, data) {
        // console.log(data);
        const r = await deleteClassifyApi(data)
        dispatch('getClassify')
    },
}

export const getters = {
    //题库管理系统里form表单分类转换
    classifyMap: state => {
        const map = {}
        state.tableData.forEach(item => {
            map[item.id] = item.name
        });
        return map
    }

}